home *** CD-ROM | disk | FTP | other *** search
- Path: news.uni-stuttgart.de!schweikh
- From: schweikh@itosun.ito.uni-stuttgart.de (Jens Schweikhardt)
- Newsgroups: comp.lang.c
- Subject: Re: cpp question
- Date: 1 Feb 1996 07:33:15 GMT
- Organization: Comp.Center (RUS), U of Stuttgart, FRG
- Message-ID: <4epqbr$206q@info4.rus.uni-stuttgart.de>
- References: <4drm99$j0m@peabody.colorado.edu> <4eloq7$h9u@bcfreenet.seflin.lib.fl.us>
- NNTP-Posting-Host: itosun.ito.uni-stuttgart.de
-
- In article <4eloq7$h9u@bcfreenet.seflin.lib.fl.us>,
- Ralph Silverman <z007400b@bcfreenet.seflin.lib.fl.us> wrote:
- :WOOD JAMEY RYAN (woodjr@rintintin.Colorado.EDU) wrote:
- :: I have something like this:
- :
- :: #define USERLEN 8
- :: #define HOSTLEN 15
- :
- :: char name[] = "woodjr";
- :: char host[] = "really.long.hostname.com";
- :: char s[100];
- :
- :: sprintf(s, "%.USERLENs@%.HOSTLENs", name, host);
- :
- :: And I want cpp to parse the sprintf line to:
- :
- :: sprintf(s, "%.8s@%.15s", name, host);
- :
- :: Which it (of course) isn't doing. Is there some syntax I
- :: can use to get it to do this?
- :
- :: Thankyou,
- :: Jamey Wood
- :
- :--
- :***********begin r.s. response**********
- :
- : cpp will not expand macro into
- : string bounded by
- : ""
- : .
- :
- :***********end r.s. response************
- #### begin r.s. criticism #### YUCK!
-
- Not too helpful an answer I think.
- There are solutions to the original poster's problem.
- One of them is, if you know that USERLEN is 8 everywhere,
- just use a
-
- #define USERLEN "8"
- #define HOSTLEN "15"
-
- and use the concatenation of string literals:
-
- sprintf(s, "%." USERLEN "s@%." HOSTLEN "s", name, host);
-
- Another way, where USERLEN may even be a runtime variable is to
- use * as the precision specifier and pass another arg to sprintf.
- E.g.
-
- printf ("%*s", num_spaces, "");
-
- will print num_spaces spaces. Technically, * is used to specify _width_ here,
- not _precision_. But you may also use
- printf ("%*.*s", width, precision, string);
- You get the idea.
-
- For more information contact your friendly printf(3) manual page :-)
-
- cc: to original poster
-
- #### end r.s. criticism #### YUCK!
-
- --
- SIGSIG -- signature too long (core dumped)
-